﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChuanYe.CountyFireManagement.Api.Models;
using ChuanYe.CountyFireManagement.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ChuanYe.CountyFireManagement.Api.Controllers
{
    /// <summary>
    /// 消息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        /// <summary>
        ///  获取消息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> Get(MessageSearchRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                result.FirstParam = BLL.MessageBLL.Instance.GetMessage(obj.MessageId,obj.FireId,
                                                                       obj.AddressCounty,obj.AddressTown,obj.AddressVillage,obj.IsRead,
                                                                       obj.MessgeTypes,obj.MessageSendTypes,obj.TargetUserId);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/Message/Get Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  更改消息状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> ChangeMessageReadStatus(ChangeMessageReadStatusRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                result.FirstParam = BLL.MessageBLL.Instance.ChangeMessageReadStatus(obj.MessageId,(short?)obj.IsRead);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/Message/ChangeMessageReadStatus Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


    }
}